package com.ruoyi.overtime.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.overtime.domain.HrOvertimeApplication;
import com.ruoyi.overtime.service.IHrOvertimeApplicationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 加班申请Controller
 * 
 * @author gy
 * @date 2025-05-20
 */
@RestController
@RequestMapping("/overtime/overtime")
public class HrOvertimeApplicationController extends BaseController
{
    @Autowired
    private IHrOvertimeApplicationService hrOvertimeApplicationService;

    /**
     * 查询加班申请列表
     */
    @PreAuthorize("@ss.hasPermi('overtime:overtime:list')")
    @GetMapping("/list")
    public TableDataInfo list(HrOvertimeApplication hrOvertimeApplication)
    {
        startPage();
        List<HrOvertimeApplication> list = hrOvertimeApplicationService.selectHrOvertimeApplicationList(hrOvertimeApplication);
        return getDataTable(list);
    }

    /**
     * 导出加班申请列表
     */
    @PreAuthorize("@ss.hasPermi('overtime:overtime:export')")
    @Log(title = "加班申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HrOvertimeApplication hrOvertimeApplication)
    {
        List<HrOvertimeApplication> list = hrOvertimeApplicationService.selectHrOvertimeApplicationList(hrOvertimeApplication);
        ExcelUtil<HrOvertimeApplication> util = new ExcelUtil<HrOvertimeApplication>(HrOvertimeApplication.class);
        util.exportExcel(response, list, "加班申请数据");
    }

    /**
     * 获取加班申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('overtime:overtime:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hrOvertimeApplicationService.selectHrOvertimeApplicationById(id));
    }

    /**
     * 新增加班申请
     */
    @PreAuthorize("@ss.hasPermi('overtime:overtime:add')")
    @Log(title = "加班申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HrOvertimeApplication hrOvertimeApplication)
    {
        return toAjax(hrOvertimeApplicationService.insertHrOvertimeApplication(hrOvertimeApplication));
    }

    /**
     * 修改加班申请
     */
    @PreAuthorize("@ss.hasPermi('overtime:overtime:edit')")
    @Log(title = "加班申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HrOvertimeApplication hrOvertimeApplication)
    {
        return toAjax(hrOvertimeApplicationService.updateHrOvertimeApplication(hrOvertimeApplication));
    }

    /**
     * 删除加班申请
     */
    @PreAuthorize("@ss.hasPermi('overtime:overtime:remove')")
    @Log(title = "加班申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hrOvertimeApplicationService.deleteHrOvertimeApplicationByIds(ids));
    }
}
